package com.girl.service;

import com.girl.domain.Girl;
import com.girl.enums.ResultEnum;
import com.girl.exception.GrilExecption;
import com.girl.repository.GirlRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * Created by zzy on 2017/12/10.
 */
@Service
public class GirlService {

    @Autowired
    private GirlRepository girlRepository;

    @Transactional
    public void insertTwo(){
        Girl a=new Girl();
        Girl b=new Girl();
        a.setAge(18);
        a.setCupSize("Z");
        b.setAge(19);
        b.setCupSize("GGGGG");
        girlRepository.save(a);
        girlRepository.save(b);
    }

    public void getAge(Integer id) throws Exception {
        Girl girl=girlRepository.findOne(id);
        Integer age=girl.getAge();

            if (age < 10) {
                throw new GrilExecption(ResultEnum.PRIMARY_SCHOOL);
            } else if (age >= 10 && age < 16) {
                throw new GrilExecption(ResultEnum.MIDDLE_SCHOOL);
            }

    }

    /**
     *
     * @param id
     * @return
     */
    public Girl findOne(Integer id){
        return girlRepository.findOne(id);
    }
}
